const initialState = {
  carts: [
    {
      good_id: 1,
      good_name: "首款海绵包包",
      color: "颜色",
      price: 68,
      num: 1,
    },
    {
      good_id: 2,
      good_name: "首款海绵包包",
      color: "颜色",
      price: 68,
      num: 1,
    },
  ],
};

export default (state = initialState, { type, payload }) => {
  console.log(type, payload);
  // Object.assign 浅拷贝
  let newState = JSON.parse(JSON.stringify(state));
  switch (type) {
    case "ADD":
      newState.carts[payload.index].num+=1;
      break;
    case "SUB":
      newState.carts[payload.index].num-=1;
    default:
      break;
  }
  return newState;
};
